package ym.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ym.mapper.AdminRoleMapper;
import ym.pojo.AdminRole;
import ym.service.AdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminRoleServiceImpl implements AdminRoleService {
    @Autowired
    private AdminRoleMapper adminRoleMapper;

    @Override
    public void add(AdminRole adminRole) {
        adminRoleMapper.insert(adminRole);
    }

    @Override
    public void update(AdminRole adminRole) {
        adminRoleMapper.updateById(adminRole);
    }

    @Override
    public void delete(Integer id) {
        adminRoleMapper.deleteById(id);
    }

    @Override
    public AdminRole findById(Integer id) {
        return adminRoleMapper.selectById(id);
    }

    @Override
    public List<AdminRole> findAll() {
        return adminRoleMapper.selectList(null);
    }

    @Override
    public Page<AdminRole> search(String search, int page, int size) {
        QueryWrapper<AdminRole> queryWrapper = new QueryWrapper<>();
        if (search != null) {

        }
        return adminRoleMapper.selectPage(new Page(page, size), queryWrapper);
    }

    @Override
    public void deleteByAdminId(Integer adminId) {
        QueryWrapper<AdminRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("adminId", adminId);
        adminRoleMapper.delete(queryWrapper);
    }

    @Override
    public void deleteByRoleId(Integer roleId) {
        QueryWrapper<AdminRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roleId", roleId);
        adminRoleMapper.delete(queryWrapper);

    }
}
